package com.example.tarea2;


import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;

public class gridview extends Activity {
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gridview);
		
		final GridView grid = (GridView) findViewById(R.id.gridView1);
		
		final ArrayAdapter gridView_adapter = ArrayAdapter.createFromResource( this, R.array.animales , android.R.layout.simple_list_item_1);
		gridView_adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
		grid.setAdapter(gridView_adapter);
		
		grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View v, int posicion, long id) {
				// TODO Auto-generated method stub
				
				switch (posicion)
            	{
	            	 case 0:
	            		 MediaPlayer sound= MediaPlayer.create(getApplicationContext(), R.raw.caballo);
	            		 sound.start();
	            		 break;
	         
	            	 case 1:
	            		 MediaPlayer sound1= MediaPlayer.create(getApplicationContext(), R.raw.cordero);
	            		 sound1.start();
	            		 break;
	         
	            	 case 2:
	            		 MediaPlayer sound2= MediaPlayer.create(getApplicationContext(), R.raw.gato);
	            		 sound2.start();
	               	  	 break;    	  
	         
	            	 case 3:
	            		 MediaPlayer sound3= MediaPlayer.create(getApplicationContext(), R.raw.mono);
	            		 sound3.start();
	            		 break;    	  
	         
	            	 case 4:
	            		 MediaPlayer sound4= MediaPlayer.create(getApplicationContext(), R.raw.pajaro);
	            		 sound4.start();
	            		 break;    	  
	         
	            	 case 5:
	            		 MediaPlayer sound5= MediaPlayer.create(getApplicationContext(), R.raw.perro);
	            		 sound5.start();
	            		 break;

            	}
			}
		});

     
	}
}
